/*
 * @Description: 账单详情api
 * @Author: tao.xie
 * @Date: 2019-03-29 11:39:06
 * @Last Modified by:   tao.xie
 * @Last Modified time: 2019-03-29 11:39:06
 */
import MallBillModel from '../model/MallBillModel'
import RouteBillModel from '../model/RouteBillModel'
import ajaxAsync from 'vue-xiaobu-utils'
import TradeBillModel from '../model/TradeBillModel'

let BUS_CARD_INSTANCE = 'jhx_buscard' // 云卡卡实例

/**
 *商城账单查询
 *
 * @param {String} tradeno 支付流水号
 */
async function getMallBill(tradeno) {
  let rs = await ajaxAsync('/vcard/mall/bill/get', { TRADE_NO: tradeno })
  let mallBill
  mallBill = new MallBillModel(
    rs.TITLE,
    rs.PAY_NAME,
    rs.BANK_CARD_NO,
    rs.ORDER_NO,
    rs.ORDER_PRICE,
    rs.ORDER_STATUS,
    rs.CREATE_TIME,
    rs.PAY_TIME,
    rs.TRADE_NO
  )
  // mallBill = new MallBillModel(
  //   '商城订单-普通商品-衣服',
  //   '中国交通银行',
  //   '8888',
  //   '1234567890',
  //   '12.12',
  //   1,
  //   '2018-12-12 19:20:31',
  //   '2018-12-12 19:25:31'
  // )
  return mallBill
}
/**
 *行程账单查询
 *
 * @param {String} tradeno 支付流水号
 */
async function getRouteBill(tradeno) {
  let rs = await ajaxAsync('/vcard/route/bill/list', { TRADE_NO: tradeno })

  let routeBill
  let tradeBillList = []

  if (rs.TRADE_BILLS) {
    rs.TRADE_BILLS.map(item => {
      tradeBillList.push(
        new TradeBillModel(item.TRADE_NO, item.TITLE, item.TRADE_SCENE)
      )
    })
  }
  routeBill = new RouteBillModel(
    rs.IS_SUPPLEMENT,
    tradeBillList,
    rs.TITLE,
    rs.PAY_NAME,
    rs.BANK_CARD_NO,
    rs.POS_BILL_NO,
    rs.TRADE_NO,
    rs.PAY_FEE,
    rs.STATE,
    rs.TRADE_TIME,
    rs.PAY_TIME,
    rs.REFUND_REASON
  )

  // for (let i = 0; i < 8; i++) {
  //   tradeBillList.push(
  //     new TradeBillModel('098765432' + i, '乘坐公交-11路-补扣' + i)
  //   )
  // }

  // routeBill = new RouteBillModel(
  //   tradeBillList.length > 0 ? 1 : 0,
  //   1,
  //   tradeBillList,
  //   '乘坐公交-11路',
  //   '杭州银行储蓄卡',
  //   '6598',
  //   '1234567890',
  //   '0987654321',
  //   '2.00',
  //   -2,
  //   3,
  //   '2019年2月13日 19:22:12',
  //   '2019年2月13日 19:22:13'
  // )
  return routeBill
}

async function getUnpayCountConfig() {
  let postData = {
    CARD_INSTANCE_ID: BUS_CARD_INSTANCE
  }
  // 协议请求
  let body = await ajaxAsync('/vcard/instance/config', postData)
  return body.QRCODR_POSBILL_LIMIT || 0
}

export { getMallBill, getRouteBill, getUnpayCountConfig }
